import { defineConfig } from 'vite'
import reactRefresh from '@vitejs/plugin-react-refresh'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  console.log('命令：', command)
  console.log('模式：', mode)
  return {
    // base: '/vite-react-blog/',
    esbuild: {
      // 解决每个组件需要引入react的问题
      jsxInject: `import React from 'react'`
    },
    plugins: [reactRefresh()],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    server: {
      host: '0.0.0.0'
    },
    build: {
      chunkSizeWarningLimit: 1024,
      terserOptions: {
        compress: {
          drop_console: true, // 移除日志
        }
      }
    },
    optimizeDeps: {
      include: [
        '@ant-design/colors',
        '@ant-design/icons'
      ]
    },
    css: {
      modules: {
        scopeBehaviour: 'local',
        localsConvention: 'camelCaseOnly'
      },
      preprocessorOptions: {
        less: {
          // 自定义样式
          modifyVars: {
            '@primary-color': '#42b983',
            '@link-color': '#42b983',
            '@heading-color': '#333333',
            'hack': `true;@import "./src/styles/var.less";`
          },
          javascriptEnabled: true,
        }
      }
    }
  }
})
